import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.geom.Rectangle2D;

import javax.swing.*;


public class Board extends JPanel implements ActionListener {
	Nyan nyanCat;
	Background background;
	Timer time;
	Ground ground;
	Rectangle2D rectangle;
	
	public Board(){
		nyanCat = new Nyan();
		ground = new Ground();
		background = new Background(nyanCat.getX());
		addKeyListener(new ActionListener());
		setFocusable(true);		//allows to move left or right with keys
		time = new Timer(5 , this);		
		time.start();
	}
	
	public void actionPerformed(ActionEvent e){
		nyanCat.move();
		background.move(nyanCat.getX());
		repaint();
		
	}
	
	public void paint( Graphics g){
		super.paint(g);
		Graphics2D g2d = (Graphics2D) g;		
		background.paint(g2d);
		nyanCat.paint(g2d);
		ground.paint(g2d); // will not work
	}
	
	private class ActionListener extends KeyAdapter{
		public void keyReleased(KeyEvent e){
			nyanCat.keyReleased(e);
		}
		
		public void keyPressed(KeyEvent e){
			nyanCat.keyPressed(e);
		}
	}
		
}

